#include "work_thread.h"
#include "msg_queue.h"

static void
create_thread(pthread_t *thread, void *(*start_routine) (void *), void *arg) {
	if (pthread_create(thread,NULL, start_routine, arg)) {
		fprintf(stderr, "Create thread failed");
		exit(1);
	}
}

static void *
thread_worker(void *p) {
	struct message_queue * q = NULL;
	while (true) {
		q = skynet_globalmq_pop();
		if (q == NULL) {
			globalmq_sleep();
			continue;
		}
		// assert(q->cb);
		// q->cb(q);
	}
	return NULL;
}

pthread_t create_work_thread()
{
	pthread_t t;
	create_thread(&t, thread_worker, NULL);
	return t;
}
